<template>
  <div class="elect">
    <div class="oneElects">
      <ul>
        <li
          class="li"
          v-for="(item, idx) in Elects"
          :key="idx"
          @click="twoDatas(idx)"
          :to="item.id"
        >
          {{ item.citysh }}
        </li>
      </ul>
    </div>
    <!-- 二级导航区域 -->
    <div class="twoElects">
      <ul class="ul">
        <li
          v-for="(item, idx) in twoElect"
          :key="idx"
          :id="item.idx"
          :title="item.districtName"
        >
          {{ item.districtName }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { getInpo } from "@/api";

export default {
  name: "Elect",
  data() {
    return {
      Elects: [],
      twoElect: [],
      indexLi: 0,
    };
  },

  created() {
    getInpo().then((res) => {
      this.Elects = res.data.data;
      console.log(this.Elects);
      this.twoElect = this.Elects[0].district;
    });
  },
  updated() {
    const aLis = document.querySelectorAll(".oneElects ul li");

    for (let i = 0; i < aLis.length; i++) {
      aLis[i].style.cssText = "";
    }
    aLis[this.indexLi].style.cssText = `color: aqua;
                         border-bottom: 2px solid;
                         cursor: pointer;`;
  },
  methods: {
    // 点击一级渲染二级页面
    twoDatas(index) {
      const aLis = document.querySelectorAll(".oneElects ul li");
      this.twoElect = this.Elects[index].district;
      this.indexLi = index;
    },
  },
};
</script>

<style scoped lang="less">
.activeLi:hover {
  color: aqua;
  border-bottom: 2px solid;
  cursor: pointer;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: white;
  .elect {
    min-height: 300px;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 20px;
    .oneElects {
      display: flex;
      height: 80px;
      //   background: red;
      margin-top: 20px;
      padding: 0 20px;
      ul {
        width: 100%;
        height: 100%;
        display: flex;
        border-bottom: 2px solid #f1f1f1;
        align-items: center;
        li {
          margin: 0 20px 0 0;
          padding: 30px 0 10px 0;
          font-size: 25px;
          line-height: 40px;
          cursor: pointer;

          &:active {
            color: yellow;
          }
        }
      }
    }
    .twoElects {
      display: flex;
      height: 40px;

      .ul {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        text-align: center;
        margin: 20px 0;

        li {
          margin: 20px;
          padding: 10px;
        }
      }
    }
  }
}
</style>
